$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'upk/upkcart/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'ID', width: 50, key: true },
			{ label: '用户标识(数字0：未插入)', name: 'userId', index: 'USER_ID', width: 80 }, 			
			{ label: '商品标识(数字0：未插入)', name: 'goodId', index: 'GOOD_ID', width: 80 }, 			
			{ label: '临时登陆的购物车，用户登陆后把购物车内容添加到该用户购物车下(字符串空：未插入)', name: 'sessionId', index: 'SESSION_ID', width: 80 }, 			
			{ label: '商品的货号,取自表GOODS的GOODS_SN(字符串空：未插入)', name: 'goodsSn', index: 'GOODS_SN', width: 80 }, 			
			{ label: '商品名称,取自表GOODS的GOODS_NAME(字符串空：未插入)', name: 'goodsName', index: 'GOODS_NAME', width: 80 }, 			
			{ label: '市场价格,取自表市场价(数字0：未插入)', name: 'marketPrice', index: 'MARKET_PRICE', width: 80 }, 			
			{ label: '商品的本店价,取自表GOODS的SHOP_PRICE(数字0：未插入)', name: 'goodsPrice', index: 'GOODS_PRICE', width: 80 }, 			
			{ label: '商品的扩展属性, 取自GOODS的EXTENSION_CODE(数字0：未插入)', name: 'goodsAttr', index: 'GOODS_ATTR', width: 80 }, 			
			{ label: '取自ECS_GOODS的IS_REAL(数字0：未插入)', name: 'isReal', index: 'IS_REAL', width: 80 }, 			
			{ label: '商品的扩展属性,取自GOODS的EXTENSION_CODE(数字0：未插入)', name: 'extensionCode', index: 'EXTENSION_CODE', width: 80 }, 			
			{ label: '该商品的父商品ID,没有该值为0,有的话那该商品就是该ID的配件(数字0：未插入)', name: 'parentId', index: 'PARENT_ID', width: 80 }, 			
			{ label: '购物车商品类型;0普通;1团够;2拍卖;3夺宝奇兵(数字0：未插入)', name: 'recType', index: 'REC_TYPE', width: 80 }, 			
			{ label: '是否赠品,0否;其他, 是参加优惠活动的ID,取值于FAVOURABLE_ACTIVITY的ACT_ID(数字0：未插入)', name: 'isGift', index: 'IS_GIFT', width: 80 }, 			
			{ label: '是否邮寄(数字0：未插入)', name: 'isShipping', index: 'IS_SHIPPING', width: 80 }, 			
			{ label: '能否处理（数字0：未插入)', name: 'canHandsel', index: 'CAN_HANDSEL', width: 80 }, 			
			{ label: '该商品的属性的ID,取自GOODS_ATTR的GOODS_ATTR_ID,如果有多个,只记录了最后一个,可能是BUG（数字0：未插入)', name: 'goodsAttrId', index: 'GOODS_ATTR_ID', width: 80 }, 			
			{ label: '该商品的购买数量255,实际库存不减少(数字0：未插入)', name: 'goodAmount', index: 'GOOD_AMOUNT', width: 80 }, 			
			{ label: '操作员(字符串空：未插入)', name: 'operator', index: 'OPERATOR', width: 80 }, 			
			{ label: '创建即上传时间(数字0：未插入)', name: 'createUtc', index: 'CREATE_UTC', width: 80 }, 			
			{ label: '修改即更新时间(数字0：未插入)', name: 'modifyUtc', index: 'MODIFY_UTC', width: 80 }, 			
			{ label: '是否删除(数字0：未插入，1.未删除,2：删除，)', name: 'isDeleted', index: 'IS_DELETED', width: 80 }, 			
			{ label: '版本号(数字0：未插入)', name: 'version', index: 'VERSION', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		upkCart: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.upkCart = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.upkCart.id == null ? "upk/upkcart/save" : "upk/upkcart/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.upkCart),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "upk/upkcart/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "upk/upkcart/info/"+id, function(r){
                vm.upkCart = r.upkCart;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});